<!--
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
-->
<html>
<head>
  <title>Opensocial Data Context Tests</title>
  <script>
    function TestCase() {};
    Function.prototype.inherits = function() {};
  </script>
  <script src="../../../../main/javascript/features/opensocial-data-context/datacontext.js"></script>  
  <script src="datacontexttest.js"></script>
  <script type="text/javascript">
      DataContextTest.prototype.assertNotNull = function(a) {
        if (a === null) {
          throw("Null: " + a);
        }
      };
      DataContextTest.prototype.assertNull = function(a) {
        if (a !== null) {
          throw("Not null: " + a);
        }
      };
      DataContextTest.prototype.assertEquals = function(a, b) {
        if (a !== b) {
          throw("Not equal: " + typeof(a) + "[" + a + "] and " + typeof(b) + "[" + b + "]");
        }
      };
      
      function exposeTestFunctionNames(obj) {
        var testSource = obj ? obj.prototype : 
            (typeof RuntimeObject != 'undefined' ? RuntimeObject('test' + '*') : self);
        var testFunctionNames = [];
        for (var i in testSource) {
          if (i.substring(0, 4) == 'test' && typeof(testSource[i]) == 'function')
           testFunctionNames.push(i);
        }
        return testFunctionNames;
      }

      function runAllTests() {
        var log = function(msg, forcePage) {
          if (window.console && !forcePage) {
            console.log(msg);
            return;
          } 
          var div = document.createElement("div");
          div.appendChild(document.createTextNode(msg));
          document.body.appendChild(div); 
        };
        var obj = new DataContextTest();
        var tests = exposeTestFunctionNames(DataContextTest);
        var failed = 0;
        for (var i = 0; i < tests.length; i++) {
          log(tests[i]);
          try {
            obj[tests[i]]();
            log("OK");
          } catch (e) {
            log("FAIL: " + e);
            failed++;
          }
        }
        log("All finished. " + i + " run. " + failed + " failed.", true);
      }
    </script>  
</head>
<body>
    <input type="button" onclick="runAllTests()" value="Run tests"/>
</body>
</html>